package com.lxmes.hr.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.lxmes.hr.domain.NcPieceworkSta;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.lxmes.common.annotation.Log;
import com.lxmes.common.core.controller.BaseController;
import com.lxmes.common.core.domain.AjaxResult;
import com.lxmes.common.enums.BusinessType;
import com.lxmes.hr.domain.NcPieceworkMoneyDetail;
import com.lxmes.hr.service.INcPieceworkMoneyDetailService;
import com.lxmes.common.utils.poi.ExcelUtil;
import com.lxmes.common.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 计件工资明细Controller
 *
 * @author ruoyi
 * @date 2023-01-16
 */
@RestController
@RequestMapping("/hr/pieceworkMoneyDetail")
public class NcPieceworkMoneyDetailController extends BaseController
{
    @Autowired
    private INcPieceworkMoneyDetailService ncPieceworkMoneyDetailService;

    /**
     * 查询计件工资明细列表
     */
    @PreAuthorize("@ss.hasPermi('hr:pieceworkMoneyDetail:list')")
    @GetMapping("/list")
    public TableDataInfo list(NcPieceworkMoneyDetail ncPieceworkMoneyDetail)
    {
        startPage();
        List<NcPieceworkMoneyDetail> list = ncPieceworkMoneyDetailService.selectNcPieceworkMoneyDetailList(ncPieceworkMoneyDetail);
        return getDataTable(list);
    }

    /**
     * 导出计件工资明细列表
     */
    @PreAuthorize("@ss.hasPermi('hr:pieceworkMoneyDetail:export')")
    @Log(title = "计件工资明细", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, NcPieceworkMoneyDetail ncPieceworkMoneyDetail)
    {
        List<NcPieceworkMoneyDetail> list = ncPieceworkMoneyDetailService.selectNcPieceworkMoneyDetailList(ncPieceworkMoneyDetail);
        ExcelUtil<NcPieceworkMoneyDetail> util = new ExcelUtil<NcPieceworkMoneyDetail>(NcPieceworkMoneyDetail.class);
        util.exportExcel(response, list, "计件工资明细数据");
    }

    /**
     * 获取计件工资明细详细信息
     */
    @PreAuthorize("@ss.hasPermi('hr:pieceworkMoneyDetail:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(ncPieceworkMoneyDetailService.selectNcPieceworkMoneyDetailById(id));
    }
    @PreAuthorize("@ss.hasPermi('hr:pieceworkMoneyDetail:query')")
    @GetMapping(value = "/readTotal")
    public AjaxResult readTotal()
    {
        return AjaxResult.success(ncPieceworkMoneyDetailService.readTotal());
    }

    /**
     * 新增计件工资明细
     */
    @PreAuthorize("@ss.hasPermi('hr:pieceworkMoneyDetail:add')")
    @Log(title = "计件工资明细", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody NcPieceworkMoneyDetail ncPieceworkMoneyDetail)
    {
        return toAjax(ncPieceworkMoneyDetailService.insertNcPieceworkMoneyDetail(ncPieceworkMoneyDetail));
    }

    /**
     * 修改计件工资明细
     */
    @PreAuthorize("@ss.hasPermi('hr:pieceworkMoneyDetail:edit')")
    @Log(title = "计件工资明细", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody NcPieceworkMoneyDetail ncPieceworkMoneyDetail)
    {
        return toAjax(ncPieceworkMoneyDetailService.updateNcPieceworkMoneyDetail(ncPieceworkMoneyDetail));
    }


    /**
     * 删除计件工资明细
     */
    @PreAuthorize("@ss.hasPermi('hr:pieceworkMoneyDetail:remove')")
    @Log(title = "计件工资明细", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(ncPieceworkMoneyDetailService.deleteNcPieceworkMoneyDetailByIds(ids));
    }

    @Log(title = "计件工资明细", businessType = BusinessType.IMPORT)
    @PostMapping("/importData")
    public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception
    {
        ExcelUtil<NcPieceworkMoneyDetail> util = new ExcelUtil<>(NcPieceworkMoneyDetail.class);
        List<NcPieceworkMoneyDetail> userList = util.importExcel(file.getInputStream());
        String operName = getUsername();
        String message = ncPieceworkMoneyDetailService.imporIteminfo(userList, updateSupport, operName);
        return AjaxResult.success(message);
    }

    @PostMapping("/importTemplate")
    public void importTemplate(HttpServletResponse response)
    {
        ExcelUtil<NcPieceworkMoneyDetail> util = new ExcelUtil<>(NcPieceworkMoneyDetail.class);
        util.importTemplateExcel(response, "计件工资明细数据");
    }

}
